package com.example.business.controller;

import com.example.business.domain.Novel;
import com.example.business.service.NovelService;
import com.example.common.BaseEntity;
import com.example.common.PageVo;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p> Novel 控制器 </p>
 *
 * @author Chris
 * @since 2022/10/28 18:01
 */
@RestController
@RequestMapping("/novel")
public class NovelController {
    /**
     * 使用 slf4j 日志框架
     */
    private final static Logger log = LoggerFactory.getLogger(NovelController.class);

    private final NovelService novelService;

    public NovelController(NovelService novelService) {
        this.novelService = novelService;
    }

    @RequestMapping("/list")
    public PageVo<?> novel(Novel novel, BaseEntity baseEntity) {
        log.info("{}", novel);
        return novelService.listNovel(novel, baseEntity);
    }

    @RequestMapping("/chapter/list")
    public PageVo<?> novelChapter(Novel novel, BaseEntity baseEntity) {
        log.info("{}", novel);
        return novelService.listNovelChapter(novel, baseEntity);
    }

    @RequestMapping("/content")
    public PageVo<?> novelContent(Novel novel, BaseEntity baseEntity) {
        log.info("{}", novel);
        return novelService.listNovelChapter(novel, baseEntity);
    }

    @RequestMapping("/save")
    public String saveNovel(Novel novel) {
        log.info("{}", novel);

        novel.setNovelId(1L);
        novel.setNovelName("测试");
        novel.setNovelAuthor("测试");
        novel.setNovelWords(2L);
        novel.setDetailUrl("https://www.baidu.com/");
        novel.setStatus(1);

        novelService.save(novel);

        return "保存成功";
    }

}